import uuid
import socket

BROADCAST_PORT = 9999
# 心跳间隔（秒）
HEARTBEAT_INTERVAL = 1
# 广播间隔（秒）
BROADCAST_INTERVAL = 3
# 离线超时（秒）
OFFLINE_TIMEOUT = 5
# 重连延迟（秒）
RECONNECT_DELAY = 3
# 最大重试次数
MAX_RETRY_COUNT = 3

def get_local_ip():
    """尝试获取本机局域网IP"""
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    try:
        s.connect(('10.255.255.255', 1))
        return s.getsockname()[0]
    except Exception:
        return '127.0.0.1'
    finally:
        s.close()

def generate_uuid():
    return str(uuid.uuid4())
